package com.fragment;

import java.util.ArrayList;

import util.ApplicationConstant;

import com.activity.MainAppActivity;
import com.activity.R;
import com.google.android.gms.internal.in;

import dao.FileBookmarkRecent;
import entities.Locate;
import adapter.AdaperBookmarkRecent;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class BookmarkRecentFragment extends Fragment{
	public static ArrayList<Locate> listLocate;
	public static AdaperBookmarkRecent adaper;
	private ListView listView;
	private TextView txtTitle;
	public static LinearLayout notFoundLayout;
	private ImageView imgNotFound;
	private TextView txtNotFound;
	private ProgressDialog progressDialog;
	private String msgString;
	public MainAppActivity mainAppActivity;
	@Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);
		this.mainAppActivity = (MainAppActivity) activity;
	}
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View root=inflater.inflate(R.layout.bookmark_recent_layout, container,false);
		listView=(ListView) root.findViewById(R.id.list_history);
		txtTitle=(TextView) root.findViewById(R.id.txt_title);
		imgNotFound=(ImageView) root.findViewById(R.id.imageView_notfound);
		notFoundLayout=(LinearLayout) root.findViewById(R.id.bookmark_recent_not_found_layout);
		progressDialog=new ProgressDialog(getActivity());
		msgString=getString(R.string.deleting);
		progressDialog.setMessage(msgString);
		progressDialog.setCancelable(false);
		txtNotFound=(TextView) root.findViewById(R.id.txt_not_foundtitle);
		if(ApplicationConstant.IS_CALLING_BOOKMARK)
		{
			Log.d("--thoainguyen BookmarkRecentFragment", "bookmark");
			MainAppActivity.fileTranfer.setFileName(FileBookmarkRecent.BOOKMARK_FILE);
			listLocate=MainAppActivity.fileTranfer.loadAll();
			txtNotFound.setText(getResources().getString(R.string.not_found_bookmark));
			imgNotFound.setImageResource(R.drawable.bookmarknotfound);
			if(listLocate.size()==0)
				notFoundLayout.setVisibility(View.VISIBLE);
			else
				notFoundLayout.setVisibility(View.GONE);
			txtTitle.setText(getResources().getString(R.string.title_bookmark));
		}
		else if(ApplicationConstant.IS_CALLING_RECENT){
			Log.d("--thoainguyen BookmarkRecentFragment", "recent");
			MainAppActivity.fileTranfer.setFileName(FileBookmarkRecent.RECENT_FILE);
			listLocate=MainAppActivity.fileTranfer.loadAll();
			txtNotFound.setText(getResources().getString(R.string.not_found_recent));
			imgNotFound.setImageResource(R.drawable.recentnotfound);
			if(listLocate.size()==0)
				notFoundLayout.setVisibility(View.VISIBLE);
			else
				notFoundLayout.setVisibility(View.GONE);
			txtTitle.setText(getResources().getString(R.string.title_recent));
		}
		for(Locate locate:listLocate)
			locate.setIsChecked(false);
		adaper=new AdaperBookmarkRecent(getActivity(), R.layout.bookmark_recent_item, listLocate);
		listView.setAdapter(adaper);
		
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int position,
					long arg3) {
				// TODO Auto-generated method stub
				mainAppActivity.navigateToLocateDetail(position);
			}
		});
		return root;
	}

}
